package com.puge.cmssservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.puge.commonutils.R;
import com.puge.cmssservice.entity.CrmBanner;
import com.puge.cmssservice.service.CrmBannerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 * 首页banner表 前端控制器
 *
 * </p>
 *
 * @author testjava
 * @since 2021-06-29
 *
 * 管理员使用的后台接口
 */
@RestController
@RequestMapping("/educmss/banneradmin")
@CrossOrigin   //解决跨域问题
public class BannerAdminController {
    @Autowired
    private CrmBannerService bannerService;

    //    1,分页查询banner
    @GetMapping("pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable long page, @PathVariable long limit){
        Page<CrmBanner> pageBanner = new Page<>(page,limit);
        bannerService.page(pageBanner,null);
        return R.ok().data("items",pageBanner.getRecords()).data("total",pageBanner.getTotal());
    }


    //    2。添加banner
    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        bannerService.save(crmBanner);
        return R.ok();
    }

    //    3,根据id获取banner
    @ApiOperation(value = "获取Banner")
    @GetMapping("get/{id}")
    public R get(@PathVariable String id){
        CrmBanner banner = bannerService.getById(id);
        return R.ok().data("item",banner);
    }

    //    4,修改banner
    @ApiOperation(value = "修改Banner")
    @PostMapping("update")
    public R updateById(@RequestBody CrmBanner banner){
        bannerService.updateById(banner);
        return R.ok();
    }

    //5，删除banner
    @ApiOperation(value = "删除banner")
    @DeleteMapping("remove/{id}")
    public R remove(@PathVariable String id){
        bannerService.removeById(id);
        return R.ok();
    }

}

